<?php
if(!@$_GET['page_number']) $page_number=1; else $page_number=$_GET['page_number'];
$start = (($page_number-1) * $max_results);
if($p!='hocphi'){
	$select = "*";
	$from = $p;
	if($p != 'users') $where = "WHERE `delete`=0"; else $where = " WHERE `delete`=0 AND id<>25 ";
	$limit = "LIMIT {$start},{$max_results}";
}else{
	$select = "hocphi.*,concat(ho,' ',ten) as hoten";
	$from = 'hocphi,hocvien';
	$where = "WHERE hocphi.`delete`=0 AND hocvien_id=hocvien.id";
	$limit = "LIMIT {$start},{$max_results}";
}
$g = 0;
$sql = $qt->select($select,$from,$where,$limit) or die ('<p class="error">Không truy vấn được</p>');

$link = "administrator.php?p={$page}&page_number=";
$sql1 = $qt->select($select,$from,$where) or die ('<p class="error">Không truy vấn được</p>');
$total = mysql_num_rows($sql1);

$total_pages = ceil($total / $max_results);
if($total_pages > 1){
	if($page_number > 1){
		$prev = ($page_number - 1);
		$phantrang .= "<a href='{$link}{$prev}'>Trang trước</a>";
	}
	for($i = $page_number - 5; $i <= $page_number + 5 & $i <= $total_pages; $i++){
		if($page_number == $i){
			$phantrang .= "<a href='{$link}{$i}' style='color:#F00; font-weight:bold; background-color:#ffffcc'>{$i}</a>";
		} elseif($i>0) {
			$phantrang .= "<a href='{$link}{$i}'>{$i}</a>";
		}
	}
	if($page_number < $total_pages){
		$next = ($page_number + 1);
		$phantrang .= "<a href='{$link}{$next}'>Trang sau</a>";
	}
}